package com.pointi.sysChecker;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class sysLogManager
{
	public static void mLog(String inString) {
		System.out.println(inString) ;
	}	
	public static void mPrint(String inString) {
		System.out.println(inString) ;
	}
	public static void printTXT(String inFilePath, String inFileName, String content)
	{
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd") ;
		String filePath = inFilePath ;
		String fileName = "" ;
		File dir = new File(filePath) ;
		if (!dir.exists()) { dir.mkdirs() ; }
		if(inFileName == null) {
			fileName = filePath + "LOG_" + formatter.format(new Date()) + ".txt" ;
		} else {
			fileName = filePath + "LOG_" + formatter.format(new Date()) + "_" + inFileName + ".txt" ;
		}		
		File file = new File(fileName) ;
		if (fileName.length() == 0) {
			try {
				FileWriter file_writer = new FileWriter(file);
				BufferedWriter buff_writer = new BufferedWriter(file_writer);
				PrintWriter print_writer = new PrintWriter(buff_writer,true);
				print_writer.println(content);
				if(print_writer.checkError()) { System.out.println("Print Writer Error !!"); }
				file.createNewFile();
				print_writer.close();
			} catch (Exception e) {
				System.out.println("IO Exceiption !!");
				e.printStackTrace();
			}
		} else {
			try {
				BufferedWriter buff_writer = new BufferedWriter(new FileWriter(file, true));
				PrintWriter print_writer = new PrintWriter(buff_writer,true);
				print_writer.println(content);
				if(print_writer.checkError()) { System.out.println("Print Writer Error !!"); }
				print_writer.close();
			} catch (Exception e) {
				System.out.println("IO Exceiption !!");
				e.printStackTrace();
			}
		}
	}
}
